<?php 
/////////////////////////////////////////////////////////////////////////
// PHPMailer - PHP paging class
//
// Class for Generate links to navigate based on query result pages
//
//
// 
//////////////////////////////////////////////////////////////////////////////

/**
 * PHPMailer - PHP Paging  class
 * @package PHPPaging
 * @author   Pramode P Paul
*/

class page{
	public $pageDisplay;
	var $strError;
	function selectpage($fields='*',$where,$order,$start,$length,$table,$link){
		///print_r(func_get_args() );
		$result		= "";
		$noPage=0;
		$length=(int)$length;
		$start=(int)$start;
		$where		= isset($where) ? "WHERE $where" : "";
		$order		= isset($order)	? "ORDER BY $order"	: " ";
		$fields		= isset($fields)? $fields	: "*";
		$sql		= "SELECT $fields FROM $table    $where $order";
		if (!is_null($start) && is_int($start) && !is_null($length) && is_int($length))
			 $sql1		= "SELECT $fields FROM $table    $where $order";
			 $sql	= "SELECT $fields FROM $table  $where $order LIMIT $start,$length";
			 $rs1	= mysql_query($sql1);
			 if(strlen(mysql_error())>0){
			 	$strError= mysql_error();
			 }else{
				 $rs= mysql_query($sql);
				 $recNo=mysql_num_rows($rs1);
				 $noPage=$recNo/$length;
				 (int)$noPage;
				 $noPage1=(int)$noPage;
				 $j=1;
				 $clr="#000000";
				 if($noPage>1){
				 while($noPage1>0){
					if($j==1){
					$st=0;}else{
					$st=($j-1)*$length;}
					if($start==$st){
						$clr="#993300";
					}else{
						$clr="#000000";
					}
					$this->pageDisplay=$this->pageDisplay."["."<a href='$link?start=$st'><font color=$clr>".$j."</font></a>"."]";
					$noPage1=$noPage1-1;
					$j=$j+1;
				 }
				 $clr="#000000";
				 $chkNo=(int)$noPage*$length;
				 if($start>$st){
						$clr="#993300";
				 }else{
						$clr="#000000";
				 }
				 if($chkNo<$recNo){
					$st=$st+$length;
					$this->pageDisplay=$this->pageDisplay."["."<a href='$link?start=$st'><font color=$clr>".$j."</font></a>"."]";
				 }
			 }
		 }
	}
		
}
